//
//  CZMainViewController.swift
//  windwb
//
//  Created by admin on 16-2-26.
//  Copyright (c) 2016年 Wind. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
     let mainTabBar = CZTabBarController()
        
        setValue(mainTabBar, forKey: "tabBar")
       //准备闭包
        mainTabBar.compreclick  =  { () -> ()  in
            print("闭包调用了")
            
        }
    
        //设置控制器
   addChildViewControllers()
 
          }
    
    
    //设置tabBar的值
    func addChildViewControllers()  {

        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title:"首页", imageName: "tabbar_home")
        
        
        let messageVC = CZMessageViewController()
//        messageVC.title = "信息"
//        messageVC.tabBarItem.image = UIImage(named: "tabbar_home")
        addChildViewController(messageVC, title: "信息", imageName: "tabbar_home")
        //占位中间加号按钮
        addChildViewController(UIViewController())
        
        let profileVC = CZProfileViewController()
//        profileVC.title = "我"
//        profileVC.tabBarItem.image = UIImage(named: "tabbar_home")
     addChildViewController(profileVC, title: "我", imageName: "tabbar_home")
        
        let discoverVC = CZDiscoverViewController()
//        discoverVC.title = "发现"
//        discoverVC.tabBarItem.image = UIImage(named: "tabbar_home")
addChildViewController(discoverVC, title:  "发现", imageName: "tabbar_home")
    }
    
    //创建方法设置tabbar
func addChildViewController(controller: UITableViewController , title : String , imageName : String) {
        
        controller.title = title
        
        controller.tabBarItem.image = UIImage(named: imageName)
    
    let hightedImage = imageName + "_highlighted"
       controller.tabBarItem.selectedImage = UIImage(named: hightedImage)?.imageWithRenderingMode( UIImageRenderingMode.AlwaysOriginal)
    
    controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
    
    //添加控制器到导航控制器
        addChildViewController(UINavigationController(rootViewController: controller))
        
    }
    

}